package com.toaa.crazymath.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.vn.toaa.brainracer.R;

public class SoundManager {
	
	private static SoundManager sInstance = null;
	
	public static SoundManager getInstance(Context context) {
		if (sInstance == null) {
			sInstance = new SoundManager(context);
		}
		return sInstance;
	}
	
	private Context mContext;
	private SoundPool mSoundPool;
	private int mSoundCorrectId;
	private int mSoundWrongId;
	private int mSoundResetId;
	
	public SoundManager(Context context) {
		mContext = context;
		mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
		mSoundCorrectId = mSoundPool.load(context, R.raw.sfx_point, 1);
		mSoundWrongId = mSoundPool.load(context, R.raw.sfx_hit, 1);
		mSoundResetId = mSoundPool.load(context, R.raw.sfx_reset, 1);
	}
	
	public void playSoundCorrect() {
		AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		mSoundPool.play(mSoundCorrectId, volume, volume, 1, 0, 1);
	}
	
	public void playSoundWrong() {
		AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		mSoundPool.play(mSoundWrongId, volume, volume, 1, 0, 1);
	}
	
	public void playSoundReset() {
		AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		mSoundPool.play(mSoundResetId, volume, volume, 1, 0, 1);
	}
	
	public void release() {
		mSoundPool.release();
	}

}
